package org.edu.modules.skill.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.edu.common.api.vo.Result;
import org.edu.common.aspect.annotation.AutoLog;
import org.edu.common.system.base.controller.BaseController;
import org.edu.common.system.query.QueryGenerator;
import org.edu.modules.skill.entity.VeJwCjZhiye;
import org.edu.modules.skill.entity.VeJwCjZhiyeUpdate;
import org.edu.modules.skill.service.IVeJwCjZhiyeService;
import org.edu.modules.skill.service.IVeJwCjZhiyeUpdateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;


/**
* @Description: 职业考试成绩修改
* @Author: jeecg-boot
* @Date:   2021-04-16
* @Version: V1.0
*/
@Api(tags="职业考试成绩修改")
@RestController
@RequestMapping("/jingsaiProject/veJwCjZhiyeUpdate")
@Slf4j
public class VeJwCjZhiyeUpdateController extends BaseController<VeJwCjZhiyeUpdate, IVeJwCjZhiyeUpdateService> {
   @Autowired
   private IVeJwCjZhiyeUpdateService veJwCjZhiyeUpdateService;

   /**
    * 分页列表查询
    *
    * @param veJwCjZhiyeUpdate
    * @param pageNo
    * @param pageSize
    * @param req
    * @return
    */
   @AutoLog(value = "职业考试成绩修改-分页列表查询")
   @ApiOperation(value="职业考试成绩修改-分页列表查询", notes="职业考试成绩修改-分页列表查询")
   @GetMapping(value = "/list")
   public Result<?> queryPageList(VeJwCjZhiyeUpdate veJwCjZhiyeUpdate,
                                  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                  HttpServletRequest req) {
       QueryWrapper<VeJwCjZhiyeUpdate> queryWrapper = QueryGenerator.initQueryWrapper(veJwCjZhiyeUpdate, req.getParameterMap());
       Page<VeJwCjZhiyeUpdate> page = new Page<VeJwCjZhiyeUpdate>(pageNo, pageSize);
       IPage<VeJwCjZhiyeUpdate> pageList = veJwCjZhiyeUpdateService.page(page, queryWrapper);
       return Result.ok(pageList);
   }

   /**
    *   添加
    *
    * @param veJwCjZhiyeUpdate
    * @return
    */
   @AutoLog(value = "职业考试成绩修改-添加")
   @ApiOperation(value="职业考试成绩修改-添加", notes="职业考试成绩修改-添加")
   @PostMapping(value = "/add")
   public Result<?> add(@RequestBody VeJwCjZhiyeUpdate veJwCjZhiyeUpdate) {
       veJwCjZhiyeUpdateService.save(veJwCjZhiyeUpdate);
       return Result.ok("添加成功！");
   }

   /**
    *  编辑
    *
    * @param veJwCjZhiyeUpdate
    * @return
    */
   @AutoLog(value = "职业考试成绩修改-编辑")
   @ApiOperation(value="职业考试成绩修改-编辑", notes="职业考试成绩修改-编辑")
   @PutMapping(value = "/edit")
   public Result<?> edit(@RequestBody VeJwCjZhiyeUpdate veJwCjZhiyeUpdate) {
       veJwCjZhiyeUpdateService.updateById(veJwCjZhiyeUpdate);
       return Result.ok("编辑成功!");
   }

   /**
    *   通过id删除
    *
    * @param id
    * @return
    */
   @AutoLog(value = "职业考试成绩修改-通过id删除")
   @ApiOperation(value="职业考试成绩修改-通过id删除", notes="职业考试成绩修改-通过id删除")
   @DeleteMapping(value = "/delete")
   public Result<?> delete(@RequestParam(name="id",required=true) String id) {
       veJwCjZhiyeUpdateService.removeById(id);
       return Result.ok("删除成功!");
   }

   /**
    *  批量删除
    *
    * @param ids
    * @return
    */
   @AutoLog(value = "职业考试成绩修改-批量删除")
   @ApiOperation(value="职业考试成绩修改-批量删除", notes="职业考试成绩修改-批量删除")
   @DeleteMapping(value = "/deleteBatch")
   public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
       this.veJwCjZhiyeUpdateService.removeByIds(Arrays.asList(ids.split(",")));
       return Result.ok("批量删除成功!");
   }

   /**
    * 通过id查询
    *
    * @param id
    * @return
    */
   @AutoLog(value = "职业考试成绩修改-通过id查询")
   @ApiOperation(value="职业考试成绩修改-通过id查询", notes="职业考试成绩修改-通过id查询")
   @GetMapping(value = "/queryById")
   public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
       VeJwCjZhiyeUpdate veJwCjZhiyeUpdate = veJwCjZhiyeUpdateService.getById(id);
       if(veJwCjZhiyeUpdate==null) {
           return Result.error("未找到对应数据");
       }
       return Result.ok(veJwCjZhiyeUpdate);
   }

   /**
   * 导出excel
   *
   * @param request
   * @param veJwCjZhiyeUpdate
   */
   @RequestMapping(value = "/exportXls")
   public ModelAndView exportXls(HttpServletRequest request, VeJwCjZhiyeUpdate veJwCjZhiyeUpdate) {
       return super.exportXls(request, veJwCjZhiyeUpdate, VeJwCjZhiyeUpdate.class, "职业考试成绩修改");
   }

   /**
     * 通过excel导入数据
   *
   * @param request
   * @param response
   * @return
   */
   @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
   public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
       return super.importExcel(request, response, VeJwCjZhiyeUpdate.class);
   }

}
